#include "PluginWeather.h"
#include <QMutex>
#include <QLabel>
#include <QComboBox>
#include <QPushButton>
#include <QGridLayout>

PluginWeather* PluginWeather::_Instance = nullptr;

PluginWeather::PluginWeather(QWidget *parent)
	: QWidget(parent)
{
	InitUI();
}

PluginWeather::~PluginWeather()
{
}

void PluginWeather::InitUI()
{
	QGridLayout* gridLayout = new QGridLayout();
	_labelAddress = new QLabel(this);
	gridLayout->addWidget(_labelAddress, 0, 0, 1, 2, Qt::AlignLeft);
	_comboAddress = new QComboBox(this);
	gridLayout->addWidget(_comboAddress, 0, 2, 1, 4);
	_refreshBtn = new QPushButton(this);
	gridLayout->addWidget(_refreshBtn, 0, 6);

	_week1 = new QLabel(this);
	_week2 = new QLabel(this);
	_week3 = new QLabel(this);
	_week4 = new QLabel(this);
	_week5 = new QLabel(this);
	_week6 = new QLabel(this);
	_week7 = new QLabel(this);
	gridLayout->addWidget(_week1, 1, 0);
	gridLayout->addWidget(_week1, 1, 1);
	gridLayout->addWidget(_week1, 1, 2);
	gridLayout->addWidget(_week1, 1, 3);
	gridLayout->addWidget(_week1, 1, 4);
	gridLayout->addWidget(_week1, 1, 5);
	gridLayout->addWidget(_week1, 1, 6);

	_date1 = new QLabel(this);
	_date2 = new QLabel(this);
	_date3 = new QLabel(this);
	_date4 = new QLabel(this);
	_date5 = new QLabel(this);
	_date6 = new QLabel(this);
	_date7 = new QLabel(this);
	gridLayout->addWidget(_date1, 2, 0);
	gridLayout->addWidget(_date1, 2, 1);
	gridLayout->addWidget(_date1, 2, 2);
	gridLayout->addWidget(_date1, 2, 3);
	gridLayout->addWidget(_date1, 2, 4);
	gridLayout->addWidget(_date1, 2, 5);
	gridLayout->addWidget(_date1, 2, 6);

	_quality1 = new QLabel(this);
	_quality2 = new QLabel(this);
	_quality3 = new QLabel(this);
	_quality4 = new QLabel(this);
	_quality5 = new QLabel(this);
	_quality6 = new QLabel(this);
	_quality7 = new QLabel(this);
	gridLayout->addWidget(_quality1, 3, 0);
	gridLayout->addWidget(_quality1, 3, 1);
	gridLayout->addWidget(_quality1, 3, 2);
	gridLayout->addWidget(_quality1, 3, 3);
	gridLayout->addWidget(_quality1, 3, 4);
	gridLayout->addWidget(_quality1, 3, 5);
	gridLayout->addWidget(_quality1, 3, 6);

	_state1 = new QLabel(this);
	_state2 = new QLabel(this);
	_state3 = new QLabel(this);
	_state4 = new QLabel(this);
	_state5 = new QLabel(this);
	_state6 = new QLabel(this);
	_state7 = new QLabel(this);
	gridLayout->addWidget(_state1, 4, 0);
	gridLayout->addWidget(_state1, 4, 1);
	gridLayout->addWidget(_state1, 4, 2);
	gridLayout->addWidget(_state1, 4, 3);
	gridLayout->addWidget(_state1, 4, 4);
	gridLayout->addWidget(_state1, 4, 5);
	gridLayout->addWidget(_state1, 4, 6);

	_Icon1 = new QLabel(this);
	_Icon2 = new QLabel(this);
	_Icon3 = new QLabel(this);
	_Icon4 = new QLabel(this);
	_Icon5 = new QLabel(this);
	_Icon6 = new QLabel(this);
	_Icon7 = new QLabel(this);
	gridLayout->addWidget(_Icon1, 5, 0);
	gridLayout->addWidget(_Icon1, 5, 1);
	gridLayout->addWidget(_Icon1, 5, 2);
	gridLayout->addWidget(_Icon1, 5, 3);
	gridLayout->addWidget(_Icon1, 5, 4);
	gridLayout->addWidget(_Icon1, 5, 5);
	gridLayout->addWidget(_Icon1, 5, 6);

	_Height1 = new QLabel(this);
	_Height2 = new QLabel(this);
	_Height3 = new QLabel(this);
	_Height4 = new QLabel(this);
	_Height5 = new QLabel(this);
	_Height6 = new QLabel(this);
	_Height7 = new QLabel(this);
	gridLayout->addWidget(_Height1, 6, 0);
	gridLayout->addWidget(_Height1, 6, 1);
	gridLayout->addWidget(_Height1, 6, 2);
	gridLayout->addWidget(_Height1, 6, 3);
	gridLayout->addWidget(_Height1, 6, 4);
	gridLayout->addWidget(_Height1, 6, 5);
	gridLayout->addWidget(_Height1, 6, 6);

	_line = new QLabel(this);
	gridLayout->addWidget(_line, 7, 0, 1, 7);

	_low1 = new QLabel(this);
	_low2 = new QLabel(this);
	_low3 = new QLabel(this);
	_low4 = new QLabel(this);
	_low5 = new QLabel(this);
	_low6 = new QLabel(this);
	_low7 = new QLabel(this);
	gridLayout->addWidget(_low1, 8, 0);
	gridLayout->addWidget(_low1, 8, 1);
	gridLayout->addWidget(_low1, 8, 2);
	gridLayout->addWidget(_low1, 8, 3);
	gridLayout->addWidget(_low1, 8, 4);
	gridLayout->addWidget(_low1, 8, 5);
	gridLayout->addWidget(_low1, 8, 6);
	this->setLayout(gridLayout);
}

PluginWeather* PluginWeather::GetInstance(QWidget* parent /* = nullptr */)
{
	QMutex mutex;
	mutex.lock();
	if (_Instance == nullptr)
	{
		QMutex mutex;
		mutex.lock();
		_Instance = new PluginWeather(parent);
		mutex.unlock();
	}

	mutex.unlock();
	return _Instance;
}